﻿using MediaAdmin.Application.Infrastructure;
using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MediaAdmin.Controllers
{
    public partial class AccountController : Controller
    {
        [Inject]
        public IAuthProvider _authProvider { set; get; }

        //public AccountController(IAuthProvider authProvider)
        //{
        //    _authProvider = authProvider;
        //}

        public ActionResult LogOn()
        {
            return View(new LogonModel());
        }

        [HttpPost]
        public ActionResult LogOn(LogonModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            if (_authProvider.Authenticate(model.Username, model.Password))
            {
                return Redirect(returnUrl ?? Url.Action("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "incorrect username or password");
            }
            return View();
        }
    }
}
